package com.zhouxiaoge.socket.multithreading;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zmy
 */
public class Server {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            Socket socket;
            int count = 0;
            System.out.println("++++++++++++++++服务器即将启动，等待客户端连接+++++++++++++++++++");
            while (true) {
                socket = serverSocket.accept();
                ServerThread serverThread = new ServerThread(socket);
                serverThread.start();
                count++;
                System.out.println("客户端的数量：" + count);
                InetAddress inetAddress = socket.getInetAddress();
                System.out.println("当前客户端的IP: " + inetAddress.getHostAddress());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
